package com.hzqy.service.statistics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.statistics.SubscriptionDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.PmsZTreeVo;
import com.hzqy.web.vo.StatDataSubscriptionAreaVo;
import com.hzqy.web.vo.StatDataSubscriptionVo;
import com.hzqy.web.vo.SysAreaVo;
import com.hzqy.web.vo.SysProductVo;

@Service
public class SubscriptionServiceBean extends GenericServiceBean<PmsUserVo, SubscriptionDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private SubscriptionDao subscriptionDao;

	@Override
	public SubscriptionDao getEntityDao() {
		return subscriptionDao;
	}
	
	public List<PmsZTreeVo> selectAreaTree(SysAreaVo sav) {
		List<PmsZTreeVo> ptvList = new ArrayList<PmsZTreeVo>();
		if(sav.getF_sa_type()==0)
            sav.setF_sa_type(1);
		List<SysAreaVo> prvList = subscriptionDao.selectAreaTree(sav);
		for(int i=0; i<prvList.size();i++){
			PmsZTreeVo ptv = new PmsZTreeVo();
			ptv.setId(prvList.get(i).getF_sa_id()+"");
			ptv.setpId(prvList.get(i).getF_sa_codeid()+"");
			ptv.setName(prvList.get(i).getF_sa_name());
			ptvList.add(ptv);
		}
		return ptvList;
	}
	
	public Map<String,Object> selectSubscriptionList(StatDataSubscriptionVo statDataSubscriptionVo, int curPage,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = subscriptionDao.selectSubscriptionCount(statDataSubscriptionVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_sds_resolution", statDataSubscriptionVo.getF_sds_resolution());
			map.put("f_sds_productid", statDataSubscriptionVo.getF_sds_productid());
			map.put("f_sds_model", statDataSubscriptionVo.getF_sds_model());
			map.put("f_sds_type", statDataSubscriptionVo.getF_sds_type());
			map.put("beginDate", statDataSubscriptionVo.getBeginDate());
			map.put("endDate", statDataSubscriptionVo.getEndDate());
			map.put("monthDate", statDataSubscriptionVo.getMonthDate());
			map.put("weekDate", statDataSubscriptionVo.getWeekDate());
			List<StatDataSubscriptionVo> results = subscriptionDao.selectSubscriptionList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataSubscriptionVo>());
		}
		return map;
	}
	
	public Map<String,Object> selectSubscriptionExcelList(StatDataSubscriptionVo statDataSubscriptionVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = subscriptionDao.selectSubscriptionCount(statDataSubscriptionVo);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_sds_resolution", statDataSubscriptionVo.getF_sds_resolution());
			map.put("f_sds_productid", statDataSubscriptionVo.getF_sds_productid());
			map.put("f_sds_model", statDataSubscriptionVo.getF_sds_model());
			map.put("f_sds_type", statDataSubscriptionVo.getF_sds_type());
			map.put("beginDate", statDataSubscriptionVo.getBeginDate());
			map.put("endDate", statDataSubscriptionVo.getEndDate());
			map.put("monthDate", statDataSubscriptionVo.getMonthDate());
			map.put("weekDate", statDataSubscriptionVo.getWeekDate());
			List<StatDataSubscriptionVo> results = subscriptionDao.selectSubscriptionExcelList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataSubscriptionVo>());
		}
		return map;
	}
	
	public Map<String,Object> selectSubscriptionAreaList(StatDataSubscriptionAreaVo statDataSubscriptionAreaVo, int curPage,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = subscriptionDao.selectSubscriptionAreaCount(statDataSubscriptionAreaVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_sdsa_resolution", statDataSubscriptionAreaVo.getF_sdsa_resolution());
			map.put("f_sdsa_productid", statDataSubscriptionAreaVo.getF_sdsa_productid());
			map.put("f_sdsa_model", statDataSubscriptionAreaVo.getF_sdsa_model());
			map.put("f_sdsa_type", statDataSubscriptionAreaVo.getF_sdsa_type());
			map.put("f_sdsa_areaid", statDataSubscriptionAreaVo.getF_sdsa_areaid());
			map.put("beginDate", statDataSubscriptionAreaVo.getBeginDate());
			map.put("endDate", statDataSubscriptionAreaVo.getEndDate());
			map.put("monthDate", statDataSubscriptionAreaVo.getMonthDate());
			map.put("weekDate", statDataSubscriptionAreaVo.getWeekDate());
			List<StatDataSubscriptionAreaVo> results = subscriptionDao.selectSubscriptionAreaList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataSubscriptionAreaVo>());
		}
		return map;
	}
	
	public Map<String,Object> selectSubscriptionAreaExcelList(StatDataSubscriptionAreaVo statDataSubscriptionAreaVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = subscriptionDao.selectSubscriptionAreaCount(statDataSubscriptionAreaVo);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_sdsa_resolution", statDataSubscriptionAreaVo.getF_sdsa_resolution());
			map.put("f_sdsa_productid", statDataSubscriptionAreaVo.getF_sdsa_productid());
			map.put("f_sdsa_model", statDataSubscriptionAreaVo.getF_sdsa_model());
			map.put("f_sdsa_type", statDataSubscriptionAreaVo.getF_sdsa_type());
			map.put("f_sdsa_areaid", statDataSubscriptionAreaVo.getF_sdsa_areaid());
			map.put("beginDate", statDataSubscriptionAreaVo.getBeginDate());
			map.put("endDate", statDataSubscriptionAreaVo.getEndDate());
			map.put("monthDate", statDataSubscriptionAreaVo.getMonthDate());
			map.put("weekDate", statDataSubscriptionAreaVo.getWeekDate());
			List<StatDataSubscriptionAreaVo> results = subscriptionDao.selectSubscriptionAreaExcelList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataSubscriptionAreaVo>());
		}
		return map;
	}
}
